package com.mycity.dao;

import java.util.List;

import com.mycity.bean.Gamer;
import com.mycity.mapper.GamerRowMapper;
import com.mycity.mapper.UserRowMapper;

public class GameDao extends RDSDao {

	public boolean isTopContributer(int experience){
		Object params[] = { experience };
		List<Gamer> gamers = this.getTemplate().query("SELECT * from Gamification where experience>?", params, new GamerRowMapper());

		if(gamers.size()>0)
			return false;
		else
			return true;

	}

	public Gamer getGamer(int userId){
		Gamer gamer = null;
		Object params[] = { userId };
		List<Gamer> gamers = this.getTemplate().query("SELECT * from Gamification where userId=?", params, new GamerRowMapper());

		gamer = gamers.get(0);

		gamer.maxExp = isTopContributer(gamer.getExperience());


		return gamer;

	}

	public Gamer updateGamer(Gamer gamer){
		Object params[] = { gamer.getNumPosts(), gamer.getNumDiamonds(), gamer.getNumComments(), gamer.getNumStars(),
				gamer.getNumLocations(), gamer.getExperience(), gamer.getUserId()};
		this.getTemplate().update("UPDATE Gamification SET numPosts=?, numDiamonds=?, "
				+ "numComments=?, numStars=?, numLocations=?, experience=? WHERE userId=?", params);
		return gamer;

	}

}
